<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
		<title>生命体征检测云平台</title>
		<link rel="shortcut icon" href="static/logo.ico" />
		<link rel="stylesheet" href="static/css/index.css" />
		<link rel="stylesheet" href="static/layui/css/layui.css" />
		<script type="text/javascript" src="static/js/jquery.min.js"></script>
		<script src="static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="static/js/vue.js"></script>
		<script type="text/javascript" src="static/js/axios.min.js"></script>
		<style>
			html,
			body,
			#container {
				height: 100%;
				width: 100%;
			}

			.container {
				height: auto;
				width: 100%;
			}

			.container 2 {
				height: auto;
				width: 100%;
			}

			.collision-btn.disable {
				background-image: none;
				color: lightgrey;
				border-color: lightgrey;
				cursor: not-allowed;
			}

			.collision-btn.disable:hover {
				background-color: #fff;
				border-color: lightgrey;
			}

			.input-card .btn {
				margin-right: .8rem;
			}

			.amap-marker {
				opacity: 0.01;
			}

			.nav-right {
				top: 1.5rem !important;
			}

			.info {
				z-index: 999 !important;
			}

			.layui-form-label {
				width: 110px;
				font-size: 14px !important;
			}

			::-webkit-input-placeholder {
				/*Webkit browsers*/
				color: #999;
				font-size: 13px;
			}

			:-moz-placeholder {
				/*Mozilla Firefox 4 to 8*/
				color: #999;
				font-size: 13px;
			}

			::moz-placeholder {
				/*Mozilla Firefox 19+*/
				color: #999;
				font-size: 13px;
			}

			:-ms-input-placeholder {
				/*Internet Explorer 10+*/
				color: #999;
				font-size: 13px;
			}

			.layui-form-pane .layui-input {
				height: 38px !important;
			}

			.layui-form-checked span,
			.layui-form-checked:hover span {
				background-color: #063683;
			}

			.layui-form-checked i,
			.layui-form-checked:hover i {
				color: #063683;
			}

			.layui-form-checkbox i {
				height: 30px;
			}

			.layui-form-onswitch {
				border-color: #063683;
				background-color: #063683;
			}

			.layui-form-label {
				width: 116px;
			}
		</style>
		<script>
			layui.use(['form', 'layedit', 'laydate', 'dropdown'], function() {
				var rloginName = localStorage.loginName;
				var equName = localStorage.equName;
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate,
					dropdown = layui.dropdown;
				dropdown.on('click(docDemoMenu1)', function(options) {
					var othis = $(this); //当前菜单列表的 DOM 对象
					console.log(options.url)

				});
				//监听指定开关
				form.on('switch(switchmx)', function(data) {
					if (this.checked) {
						$('#mxshow').show();
						$('#mxval').val(1);
					} else {
						$('#mxshow').hide();
						$('#mxval').val(0);
					}
				});
				form.on('switch(switchxl)', function(data) {
					if (this.checked) {
						$('#xlshow').show();
						$('#xlval').val(1);
					} else {
						$('#xlshow').hide();
						$('#xlval').val(0);
					}
				});
				form.on('switch(switchhx)', function(data) {
					if (this.checked) {
						$('#hxshow').show();
						$('#hxval').val(1);
					} else {
						$('#hxshow').hide();
						$('#hxval').val(0);
					}
				});
				form.on('switch(switchxy)', function(data) {
					if (this.checked) {
						$('#xyshow').show();
						$('#xyval').val(1);
					} else {
						$('#xyshow').hide();
						$('#xyval').val(0);
					}
				});
				form.on('switch(switchwd)', function(data) {
					if (this.checked) {
						$('#wdshow').show();
						$('#wdval').val(1);
					} else {
						$('#wdshow').hide();
						$('#wdval').val(0);
					}
				});
				form.on('switch(switchsd)', function(data) {
					if (this.checked) {
						$('#sdshow').show();
						$('#sdval').val(1);
					} else {
						$('#sdshow').hide();
						$('#sdval').val(0);
					}
				});
				//时间范围
				laydate.render({
					elem: '#times',
					type: 'time',
					range: true
				});
				
				$.ajax({
					url: url + "/user/equipment/infoList?userId=" + rloginName,
					dataType: 'json',
					type: 'get',
					async: false,
					success: function(res) {
						$.each(res, function(index, item) {
							var option;
							if (item.equName != null || item.equName !=
								"" || item.equName != "null") {
								option = new Option(item.equName, item.equName);
							}
							$('#einfo').append(option); // 下拉菜单里添加元素
						}); +
						form.render("select");
						//重新渲染 固定写法
					}
				});
				$.ajax({
					url: url + "/param/code/maixiangInfo",
					dataType: 'json',
					type: 'get',
					async: false,
					success: function(res) {
						$.each(res, function(index, item) {
							var option;
							var option2;
							if (item.codeName != null || item.codeName !=
								"" || item.codeName != "null") {
								option = new Option(item.codeName, item.codeValue);
								option2 = new Option(item.codeName, item.codeValue);
							}
							$('#mxStart').append(option); // 下拉菜单里添加元素mxStart
							$('#mxEnd').append(option2);
						});
						form.render("select");
						//重新渲染 固定写法
					}
				});
				$.ajax({
					url: url + "/param/code/maixiangInfo",
					dataType: 'json',
					type: 'get',
					async: false,
					success: function(res) {
						$.each(res, function(index, item) {
							var option;
							var option2;
							if (item.codeName != null || item.codeName !=
								"" || item.codeName != "null") {
								option = new Option(item.codeName, item.codeValue);
								option2 = new Option(item.codeName, item.codeValue);
							}
							$('#mxStart').append(option); // 下拉菜单里添加元素mxStart
							$('#mxEnd').append(option2);
						});
						form.render("select");
						//重新渲染 固定写法
					}
				});
				$.ajax({
					data:{ "equId": equName },
					url: url + "/yj/settings/info",
					dataType: 'json',
					type: 'post',
					async: false,
					success: function(res) {
					$('#einfoval').val(res.equId);
					$("#einfo option[value='" + $('#einfoval').val() + "']").attr("selected", "selected");
					if (res.mxIsopen == true) {
					        $("#mxIsopen").attr("checked", "checked");
							$('#mxshow').show();
							$("#mxStart option[value='" + res.mxStart+ "']").attr("selected", "selected");
							$("#mxEnd option[value='" + res.mxEnd+ "']").attr("selected", "selected");
					} else {
					        $("#mxIsopen").removeAttr('checked');
							$('#mxshow').hide();
					}
					if (res.xlIsopen == true) {
					        $("#xlIsopen").attr("checked", "checked");
							$('#xlshow').show();
							$('#xlStart').val(res.xlStart);
							$('#xlEnd').val(res.xlEnd);
					} else {
					        $("#xlIsopen").removeAttr('checked');
							$('#xlshow').hide();
					}
					
					if (res.hxlIsopen == true) {
					        $("#hxlIsopen").attr("checked", "checked");
							$('#hxshow').show();
							$('#hxlStart').val(res.hxlStart);
							$('#hxlEnd').val(res.hxlEnd);
					} else {
					        $("#hxlIsopen").removeAttr('checked');
							$('#hxshow').hide();
					}
					
					if (res.xyIsopen == true) {
					        $("#xyIsopen").attr("checked", "checked");
							$('#xyshow').show();
							$('#xyStart').val(res.xyStart);
					} else {
					        $("#xyIsopen").removeAttr('checked');
							$('#xyshow').hide();
					}
					
					if (res.wdIsopen == true) {
					        $("#wdIsopen").attr("checked", "checked");
							$('#wdshow').show();
							$('#wdStart').val(res.wdStart);
							$('#wdEnd').val(res.wdEnd);
					} else {
					        $("#wdIsopen").removeAttr('checked');
							$('#wdshow').hide();
					}
					if (res.sdIsopen == true) {
					        $("#sdIsopen").attr("checked", "checked");
							$('#sdshow').show();
							$('#sdStart').val(res.sdStart);
							$('#sdEnd').val(res.sdEnd);
					} else {
					        $("#sdIsopen").removeAttr('checked');
							$('#sdshow').hide();
					}
					$('#btnadd').hide();
					$('#btneditor').show();
					form.render();
						console.log(res.id)
						
						// form.render("select");
						// //重新渲染 固定写法
					}
				});
			});
		</script>
	</head>
	<body>
		<div id="app">
			<input  type="hidden" value="" id="einfoval"/>
			<div style="margin-top: 70px;background-color: #e5e5e5;"></div>
			<div class="layui-panel" style="float: left; width: 10% !important;" id="pnav">

			</div>
			<div class="container" style="width: 90% !important; float: right;padding-left: 30px;">
				<div class="layui-fluid">
					<fieldset class="layui-elem-field layui-field-title">
						<legend>预警设置</legend>
						<legend style="font-size: 14px;margin-top: 10px;">检测数据超过设置的范围，就会提示风险预警</legend>
					</fieldset>
					<div class="layui-form">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">设备选择</label>
								<div class="layui-input-inline">
									<select name="modules" lay-verify="required" lay-search="" id="einfo">
										<option value="">直接选择或搜索选择</option>
									</select>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">脉象</label>
							<div class="layui-input-block">
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchmx"
									lay-text="开|关" id="mxIsopen">
								<input type="hidden" value="" id="mxval" />
							</div>
							<div class="layui-inline" id="mxshow" style="margin-top: 20px;display: none;">
								<div class="layui-input-inline" style="width: 300px;">
									<div class="layui-input-block" style="width: 300px;margin: 0;">
										<select name="interest" lay-filter="aihao" id="mxStart">
											<option value=""></option>
										</select>
									</div>
								</div>
								<div class="layui-form-mid">~</div>
								<div class="layui-input-inline" style="width: 300px;">
									<div class="layui-input-block" style="width: 300px;margin: 0;">
										<select name="interest" lay-filter="aihao" id="mxEnd">
											<option value=""></option>
										</select>
									</div>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width: 150px;">心率(次/每分钟)</label>
							<div class="layui-input-block">
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchxl"
									lay-text="开|关" id="xlIsopen">
								<input type="hidden" value="" id="xlval" />
							</div>
							<div class="layui-inline" style="margin-top: 20px;display: none;" id="xlshow">
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="xlStart" placeholder="0" autocomplete="off"
										class="layui-input">
								</div>
								<div class="layui-form-mid">-</div>
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="xlEnd" placeholder="0" autocomplete="off"
										class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width: 150px;">呼吸率(次/每分钟)</label>
							<div class="layui-input-block" >
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchhx"
									lay-text="开|关" id="hxlIsopen">
								<input type="hidden" value="" id="hxval" />
							</div>
							<div class="layui-inline" style="margin-top: 20px;display: none;" id="hxshow">
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="hxlStart" placeholder="0" autocomplete="off"
										class="layui-input">
								</div>
								<div class="layui-form-mid">-</div>
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="hxlEnd" placeholder="0" autocomplete="off"
										class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width: 150px;">血氧(%)</label>
							<div class="layui-input-block">
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchxy"
									lay-text="开|关" id="xyIsopen">
							 <input type="hidden" value="" id="xyval" />
							</div>
							<div class="layui-inline" style="margin-top: 20px;display: none;" id="xyshow">
								<div class="layui-input-inline" style="width: 400px;">
									<span style="float: left;color: #949292;line-height: 30px;margin-right: 10px;font-size: 14px;">大于</span>	<input type="text" id="xyStart" placeholder="0%" autocomplete="off"
																			class="layui-input" style="float:left;width:200px"><span style="float: left;line-height: 30px;margin-right: 10px;font-size: 14px;">%</span>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width: 150px;">温度(℃)</label>
							<div class="layui-input-block">
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchwd"
									lay-text="开|关" id="wdIsopen">
								<input type="hidden" value="" id="wdval" />
							</div>
							<div class="layui-inline" style="margin-top: 20px;display: none;" id="wdshow">
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="wdStart" placeholder="℃" autocomplete="off"
										class="layui-input">
								</div>
								<div class="layui-form-mid">-</div>
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="wdEnd" placeholder="℃" autocomplete="off"
										class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width: 150px;">湿度(%)</label>
							<div class="layui-input-block">
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchsd"
									lay-text="开|关" id="sdIsopen">
								<input type="hidden" value="" id="sdval" />
							</div>
							<div class="layui-inline" style="margin-top: 20px;display: none;" id="sdshow">
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="sdStart" placeholder="0%" autocomplete="off"
										class="layui-input">
								</div>
								<div class="layui-form-mid">-</div>
								<div class="layui-input-inline" style="width: 200px;">
									<input type="text" id="sdEnd" placeholder="0%" autocomplete="off"
										class="layui-input">
								</div>
							</div>
						</div>
						<hr />
						<div class="layui-form-item" id="btnadd">
							<div class="layui-input-block">
								<button type="submit" class="layui-btn met04" lay-submit=""
									lay-filter="demo1" v-on:click="insertSz" >立即保存</button>
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
							</div>
						</div>
						<div class="layui-form-item" style="display: none;" id="btneditor">
							<div class="layui-input-block">
								<button type="submit" class="layui-btn met04" lay-submit=""
									lay-filter="demo1" v-on:click="editorSz" >立即修改</button>
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
							</div>
						</div>
					</div>

				</div>
			</div>
			<div class="info">
				<div class="nav-left">
					<a class="login"></a>
					<a class="hometext" href="index.html" v-if="uInfoData.loginType !=1">首页</a>
					<a class="hometext" href="home.html" v-if="uInfoData.loginType == 1">首页</a>
				</div>
				<div class="nav-right">
					<ul>
						<li><a href="monitoring.html" v-if="uInfoData.loginType !=1">监测</a></li>
						<li><a href="historical_data.html" v-if="uInfoData.loginType !=1">历史数据</a></li>
						<li><a href="historical_info.html" v-if="uInfoData.loginType == 1">历史数据</a></li>
						<li><a href="call_p.html">离床报警</a></li>
						<li><a href="#">康养中心</a></li>
						<li><a href="#">中医问诊</a></li>
					</ul>
				</div>
				<div class="userinfo" id="userinfo">
					<img src="static/image/user.png" />
					<!-- <div class="red-dot"></div> -->
					<ul class="user_dropdown">
						<li class="dropdown_item user_ctrl">
							<div class="nickname">{{uInfoData.userName}}</div>
							<div class="sign_out">退出</div>
						</li>
						<li class="dropdown_item msg_item">
							<a href="user.html" target="_blank">
								<span>个人中心</span>
							</a>
						</li>
						<li class="dropdown_item msg_item">
							<a href="my_message.html" target="_blank">
								<span>我的消息</span>
								<span class="msg_unread unread_count show">5</span>
							</a>
						</li>
						<li class="dropdown_item">
							<a href="equipment.html">
								<span>设备</span>
							</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="static/js/config.js"></script>
		<script>
			$(function() {
				$("#pnav").load("public_navigation.html");
				$(".sign_out").click(function() {
				localStorage.clear();
					window.location = 'login.html'
				});
			});
			var vm = new Vue({
				el: '#app', //设置当前vue对象可以操作数据的范围,注意不要把vue对象绑定到body中，因为这样，vue需要控制整个页面的内容，效率太低了
				data: {
					uInfoData: [],
					esetinfo: []

				},
				ready: function() {
					// this.getdata();
				},
				created: function() {
					this.getdata();

				},
				methods: {
					getdata: function() {
						var rloginName = localStorage.loginName;
						console.log(rloginName);
						if (rloginName == '' || rloginName == 'null' || rloginName == undefined) {
							layer.msg('登录过期或者无权访问！', {
								time: 1000,
								end: function() {
									location.href = 'login.html'
								}
							})
						} else {
							axios({
									method: 'GET',
									url: url + "/user/userInfo/lquserOwnInfo?phoneNum=" + rloginName,
									data: {}
								})
								.then(function(response) {
									console.log(response)
									vm.uInfoData = response.data;
								})
							axios({
									method: 'GET',
									url: url + "/user/userInfo/lquserOwnInfo?phoneNum=" + rloginName,
									data: {}
								})
								.then(function(response) {
									console.log(response)
									vm.uInfoData = response.data;
								})	
						}
					},
					insertSz: function() {
						
							var rloginName = localStorage.loginName;
						var equId = $('#einfo').val();
						var mxIsopen = $('#mxval').val();
						var mxStart = $('#mxStart').val();
						var mxEnd = $('#mxEnd').val();
						var xlIsopen = $('#xlval').val();
						var xlStart = $('#xlStart').val();
						var xlEnd = $('#xlEnd').val();
						var hxlIsopen = $('#hxval').val();
						var hxlStart = $('#hxlStart').val();
						var hxlEnd = $('#hxlEnd').val();
						var xyIsopen = $('#xyval').val();
						var xyStart = $('xyStart').val();
						var wdIsopen = $('#wdval').val();
						var wdStart = $('#wdStart').val();
						var wdEnd = $('#wdEnd').val();
						var sdIsopen = $('#sdval').val();
						var sdStart = $('#sdStart').val();
						var sdEnd = $('#sdEnd').val();
						
						let data = new FormData();
						data.append('equId', einfo);
						data.append('equId', equId);
						data.append('mxIsopen', mxIsopen);
						data.append('mxStart', mxStart);
						data.append('mxEnd', mxEnd);
						data.append('xlIsopen', xlIsopen);
						data.append('xlStart', xlStart);
						data.append('xlEnd', xlEnd);
						data.append('hxlIsopen', hxlIsopen);
						data.append('hxlStart', hxlStart);
						data.append('hxlEnd', hxlEnd);
						data.append('xyIsopen', xyIsopen);
						data.append('xyStart', xyStart);
						data.append('wdIsopen', wdIsopen);
						data.append('wdStart', wdStart);
						data.append('wdEnd', wdEnd);
						data.append('sdIsopen', sdIsopen);
						data.append('sdStart', sdStart);
						data.append('sdEnd', sdEnd);
						data.append('familyId', "");
						data.append('userPhone', rloginName);
						if (data == "undefined" || data == null || data == "") {
							layer.msg('所有选项不能为空！')
						} else {
							axios({
									method: 'POST',
									url: url + "/yj/settings/addYujingSet",
									data: data //JSON.parse(JSON.stringify(sqInfo))
								})
								.then(function(response) {
									var data = response.data;
									var message = response.data.message;
									if (data.code == 0) {
										layer.msg(message, {
											time: 2000,
											end: function() {
												 location.href = 'warning_set_up.html'
											}
										})
									} else {
										layer.msg(message);
									}
								})
						}
					},
					editorSz: function() {
						
							var rloginName = localStorage.loginName;
						var equId = $('#einfo').val();
						var mxIsopen = $('#mxval').val();
						var mxStart = $('#mxStart').val();
						var mxEnd = $('#mxEnd').val();
						var xlIsopen = $('#xlval').val();
						var xlStart = $('#xlStart').val();
						var xlEnd = $('#xlEnd').val();
						var hxlIsopen = $('#hxval').val();
						var hxlStart = $('#hxlStart').val();
						var hxlEnd = $('#hxlEnd').val();
						var xyIsopen = $('#xyval').val();
						var xyStart = $('xyStart').val();
						var wdIsopen = $('#wdval').val();
						var wdStart = $('#wdStart').val();
						var wdEnd = $('#wdEnd').val();
						var sdIsopen = $('#sdval').val();
						var sdStart = $('#sdStart').val();
						var sdEnd = $('#sdEnd').val();
						
						let data = new FormData();
						data.append('equId', einfo);
						data.append('equId', equId);
						data.append('mxIsopen', mxIsopen);
						data.append('mxStart', mxStart);
						data.append('mxEnd', mxEnd);
						data.append('xlIsopen', xlIsopen);
						data.append('xlStart', xlStart);
						data.append('xlEnd', xlEnd);
						data.append('hxlIsopen', hxlIsopen);
						data.append('hxlStart', hxlStart);
						data.append('hxlEnd', hxlEnd);
						data.append('xyIsopen', xyIsopen);
						data.append('xyStart', xyStart);
						data.append('wdIsopen', wdIsopen);
						data.append('wdStart', wdStart);
						data.append('wdEnd', wdEnd);
						data.append('sdIsopen', sdIsopen);
						data.append('sdStart', sdStart);
						data.append('sdEnd', sdEnd);
						data.append('familyId', "");
						data.append('userPhone', rloginName);
						if (data == "undefined" || data == null || data == "") {
							layer.msg('所有选项不能为空！')
						} else {
							axios({
									method: 'POST',
									url: url + "/yj/settings/addYujingSet",
									data: data //JSON.parse(JSON.stringify(sqInfo))
								})
								.then(function(response) {
									var data = response.data;
									var message = response.data.message;
									if (data.code == 0) {
										layer.msg(message, {
											time: 2000,
											end: function() {
												 // location.href = 'warning_set_up.html'
											}
										})
									} else {
										layer.msg(message);
									}
								})
						}
					}
				}
			})
		</script>
	</body>
</html>